<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qqmlconnections.cpp -->
  <title>Connections QML 类型| Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-qmlmodule.html">QML Types</a></td><td >Connections QML 类型</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 
5.12.3 <span lang="zh-cn">参考指南</span></a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc"><span lang="zh-cn">目录</span></a></h3>
<ul>
<li class="level1"><a href="#properties"><span lang="zh-cn">属性</span></a></li>
<li class="level1"><a href="#details"><span lang="zh-cn">详细信息</span></a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">&nbsp;QML<span lang="zh-cn">的</span>Connection<span lang="zh-cn">s（连接）</span>
<span lang="zh-cn">类型</span></h1>
<span class="subtitle"></span>
<!-- $$$Connections-brief -->
<p>描述与信号的一般连接。 <a href="#details"><span lang="zh-cn">更多</span>...</a></p>
<!-- @@@Connections -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> <span lang="zh-cn">导入语句：</span></td><td class="memItemRight bottomAlign"> import QtQml 2.12</td></tr></table></div><ul>
<li><a href="qml-qtqml-connections-members.html"><span lang="zh-cn">
所有成员列表，包括继承成员。</span></a></li>
</ul>
<a name="properties"></a>
<h2 id="properties"><span lang="zh-cn">属性</span></h2>
<ul>
<li class="fn"><b><b><a href="qml-qtqml-connections.html#enabled-prop">enabled</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qtqml-connections.html#ignoreUnknownSignals-prop">ignoreUnknownSignals</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qtqml-connections.html#target-prop">target</a></b></b> : Object</li>
</ul>
<!-- $$$Connections-description -->
<a name="details"></a>
<h2 id="details"><span lang="zh-cn">详细信息</span></h2>
<p><span lang="zh-cn">一个</span>Connections对象创建到QML信号的连接。</p>
<p>当连接到QML中的信号时，通常的方法是创建一个“<span lang="zh-cn">on&lt;</span>Signal<span lang="zh-cn">&gt;</span>”处理程序，它在接收到信号时做出反应，如下所示:</p>
<pre class="qml">

  <span class="type"><a href="../qtquick/qml-qtquick-mousearea.html">MouseArea</a></span> {
      <span class="name">onClicked</span>: { <span class="name">foo</span>(<span class="name">parameters</span>) }
  }

</pre>
<p>然而，在某些情况下，不可能以<span lang="zh-cn">几</span>种方式连接到信号，例如:</p>
<ul>
<li>需要对同一个信号进行多次连接</li>
<li>在信号发送方范围之外创建连接</li>
<li>连接到QML中未定义的目标</li>
</ul>
<p>当需要其中任何一种时，都可以使用Connection<span lang="zh-cn">s</span>类型。</p>
<p>例如，上面的代码可以修改为使用一个Connections对象，如下所示:</p>
<pre class="qml">

  <span class="type"><a href="../qtquick/qml-qtquick-mousearea.html">MouseArea</a></span> {
      <span class="type"><a href="qml-qtqml-connections.html">Connections</a></span> {
          <span class="name">onClicked</span>: <span class="name">foo</span>(<span class="name">parameters</span>)
      }
  }

</pre>
<p>更一般地，Connections对象可以是信号发送方以外的其他对象的子对象:</p>
<pre class="qml">

  <span class="type"><a href="../qtquick/qml-qtquick-mousearea.html">MouseArea</a></span> {
      <span class="name">id</span>: <span class="name">area</span>
  }
  <span class="comment">// ...</span>

</pre>
<pre class="qml">

  <span class="type"><a href="qml-qtqml-connections.html">Connections</a></span> {
      <span class="name">target</span>: <span class="name">area</span>
      <span class="name">onClicked</span>: <span class="name">foo</span>(<span class="name">parameters</span>)
  }

</pre>
<p><b><span lang="zh-cn">参考</span> </b><a href="qtqml-index.html">Qt QML</a><span lang="zh-cn">。</span></p>
<!-- @@@Connections -->
<h2><span lang="zh-cn">属性文档</span></h2>
<!-- $$$enabled -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="enabled-prop">
<td class="tblQmlPropNode"><p>
<a name="enabled-prop"></a><span class="name">enabled</span> : <span class="type"><a href="qml-bool.html">bool</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>此属性保存项目是否接受更改事件。</p>
<p>默认情况下，该属性为<code>true</code>。</p>
<p>这个属性是在Qt 5.7中引入的。</p>
</div></div><!-- @@@enabled -->
<br/>
<!-- $$$ignoreUnknownSignals -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="ignoreUnknownSignals-prop">
<td class="tblQmlPropNode"><p>
<a name="ignoreUnknownSignals-prop"></a><span class="name">ignoreUnknownSignals</span> : <span class="type"><a href="qml-bool.html">bool</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>通常，连接到一个不存在的信号会产生运行时错误。</p>
<p>如果此属性设置为<code>true</code>，则此类错误将被忽略。<br>
如果您想连接到不同类型的对象，为每个对象处理不同的信号集，那么这是非常有用的。</p>
</div></div><!-- @@@ignoreUnknownSignals -->
<br/>
<!-- $$$target -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="target-prop">
<td class="tblQmlPropNode"><p>
<a name="target-prop"></a><span class="name">target</span> : <span class="type">Object</span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>此属性保存发送信号的对象。</p>
<p>I如果未设置此属性，则目标默认为Connection的父节点。</p>
<p>如果设置为null，则不进行连接，并且忽略任何信号处理程序，直到目标不为空为止。</p>
</div></div><!-- @@@target -->
<br/>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
